(function () {
    'use strict';

    var serviceId = 'datacontext';
    angular.module('app').factory(serviceId,
        ['page.resource', 'menu.resource', 'account.resource', datacontext]);

    function datacontext(pageResource, menuResource, accountResource) {
        return {
            getPages: function (culture) {
                return pageResource.query(culture).$promise;
            },
            saveChanges: function (page) {
                return pageResource.save(page).$promise;
            },
            getMenu: function (culture, name) {
                return menuResource.query({ culture: culture, menuName: name }).$promise;
            },
            getUserName: function () {
                return accountResource.query().$promise;
            },
            isAuthenticated: function () {
                return accountResource.isAuthenticated().$promise;
            }
        };
    }
})();